package com.mp3s.stock;

import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.mp3s.backtest_a.backtestA;
import com.mp3s.plugin_quote.quote;
import com.mp3s.plugin_quote.full.fullQuote;
import com.mp3s.plugin_quote.qday.qday;
import com.mp3s.stock.history.history;
import com.mp3s.strategy_a.strategyA;

import cn.hutool.core.util.StrUtil;


@SpringBootApplication
public class StockApplication {

	public static String stockId = "sz000833,sz002966,sh600889,sh600476";//"sh601128,sz002125,sz001205,sz002926";

	public static void main(String[] args) {

		// 接受外部参数
		if(args.length >= 1){
			StockApplication.stockId = args[0];
			System.out.println(args[0]);
		}else{
			
			System.out.println(">>>>>>>>>>>>NULL<<<<<<<<<<<");
		}

		SpringApplication.run(StockApplication.class, args);
	}

	@Component
	public class StockApplicationListener implements ApplicationListener<ApplicationReadyEvent> {

		@Override
		public void onApplicationEvent(@SuppressWarnings("null") ApplicationReadyEvent event) {
			
			System.out.println("Spring Boot 应用已经启动完毕！");

			// if(1>0){
			// 	db_sqlite_pool dsd = new db_sqlite_pool();
			// 	dsd.init();
			// 	return;
			// }
			
			String stockId = StockApplication.stockId;
			List<String> stockList = StrUtil.split(stockId, ',');

			// 构建历史库
			history h  = new history();
			h.CreateTabeIfNotExist();
			
			//from file load stock list
			quote q = new quote();
			q.load_stocks();
			
			// 获取新行情
			boolean bfullSotck = false;	//false，只对传入的list进行监控；否则，为全市场

			if(false == bfullSotck){

				qday c = new qday();
				c.start(stockId,"",h);
				
				//启动策略
				strategyA s = new strategyA();
				s.init(stockList);
				s.start();

			}
			else{
				
				fullQuote f = new fullQuote();
				f.start(q.getStockList(), "", h);
				
				//启动策略
				strategyA s = new strategyA();
				s.init(q.getStockList());
				s.start();
			}
			
			//发邮件
			// MailImpl m = new MailImpl();
			// m.sendEmail("","h","c");

			// backtest
			backtestA bta = new backtestA();
			bta.init();
			bta.start();

			// System.out.println("11111111");
	
			
		}
	}
}


